home *** CD-ROM | disk | FTP | other *** search
/ io Programmo 10 / ioProg_10.iso / soft / sdk20 / jsdk05.cab / Samples / Debugger / Java Debugger / Helpers / JDbgHlpr / Process.cpp < prev    next >
Encoding:
C/C++ Source or Header  |  1997-09-25  |  2.0 KB  |  90 lines

  1. /*
  2.  * process.cpp - Native methods.
  3.  *
  4.  * (C) Copyright 1996 Microsoft Corporation
  5.  */
  6.  
  7.  
  8. /* Headers
  9.  **********/
  10.  
  11. #include "project.hpp"
  12. #pragma hdrstop
  13.  
  14. #include "DebuggeeProcess.h"
  15.  
  16.  
  17. /****************************** Public Functions *****************************/
  18.  
  19.  
  20. BOOL JavaStringToANSIString(Hjava_lang_String *phjsCommandLine, PSTR *ppszANSI)
  21. {
  22.     int ncchLen;
  23.  
  24.     // (+ 1) for null terminator.
  25.     ncchLen = javaStringLength(phjsCommandLine) + 1;
  26.  
  27.     *ppszANSI = (PSTR)LocalAlloc(0, ncchLen);
  28.  
  29.     if (*ppszANSI)
  30.         javaString2CString(phjsCommandLine, *ppszANSI, ncchLen);
  31.  
  32.     return(*ppszANSI != NULL);
  33. }
  34.  
  35.  
  36. /***************************** Exported Functions ****************************/
  37.  
  38.  
  39. /* A debugger requires a way to get the process ID of its debuggee process. */
  40.  
  41. void __cdecl DebuggeeProcess_CreateSuspendedProcess(HDebuggeeProcess *hdp, Hjava_lang_String *phjsCommandLine)
  42. {
  43.     PSTR pszCommandLine;
  44.  
  45.     hdp->m_nMainThreadHandle = 0;
  46.     hdp->m_nProcessID = 0;
  47.  
  48.     if (JavaStringToANSIString(phjsCommandLine, &pszCommandLine))
  49.     {
  50.         STARTUPINFO si;
  51.         PROCESS_INFORMATION pi;
  52.  
  53.         ZeroMemory(&si, sizeof(si));
  54.         si.cb = sizeof(si);
  55.     
  56.         if (CreateProcess(NULL, pszCommandLine, NULL, NULL, FALSE, CREATE_SUSPENDED, NULL, NULL, &si, &pi))
  57.         {
  58.             hdp->m_nMainThreadHandle = (int)(pi.hThread);
  59.             hdp->m_nProcessID = pi.dwProcessId;
  60.  
  61.             CloseHandle(pi.hProcess);
  62.         }
  63.         else
  64.             SignalError(0, "java/io/IOException", "CreateProcess");
  65.  
  66.         LocalFree(pszCommandLine);
  67.         pszCommandLine = NULL;
  68.     }
  69.     else
  70.         SignalError(0, JAVAPKG "OutOfMemoryError", 0);
  71.  
  72.     return;
  73. }
  74.  
  75.  
  76. void __cdecl DebuggeeProcess_ResumeProcess(HDebuggeeProcess *hdp)
  77. {
  78.     if (hdp->m_nMainThreadHandle != NULL)
  79.     {
  80.         if (ResumeThread((HANDLE)(hdp->m_nMainThreadHandle)) == 0xffffffff)
  81.             SignalError(0, "java/io/IOException", "ResumeThread");
  82.  
  83.         CloseHandle((HANDLE)(hdp->m_nMainThreadHandle));
  84.         hdp->m_nMainThreadHandle = 0;
  85.     }
  86.  
  87.     return;
  88. }
  89.  
  90.